//
//  MyAcountSettingVC.m
//  shortvideoplay
//
//  Created by tikeios_002 on 2024/7/1.
//

#import "MyAcountSettingVC.h"
#import "My_editTableViewCell.h"
#import "MyChangePassVC.h"
#import "QZBackListVC.h"
#import "MyPrivacySettingVC.h"
#import "CSJADLoading.h"

@interface MyAcountSettingVC ()<UITableViewDelegate,UITableViewDataSource>
@property (strong,nonatomic)UITableView * acountTableView;
@property (strong,nonatomic)NSArray * listArr;
@end

@implementation MyAcountSettingVC

-(void)showTextViewNavViewTo1{
    NSMutableArray * showTextViewNavViewNameArrTo1 = [NSMutableArray new];
    UIView * showTextViewNavViewViewTo1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    showTextViewNavViewViewTo1.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:showTextViewNavViewViewTo1];
    UILabel * showTextViewNavViewLabelTo1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    NSInteger showTextViewNavViewNumberTo1 = arc4random_uniform(20);
    NSLog(@"：%ld", (long)showTextViewNavViewNumberTo1);
    showTextViewNavViewLabelTo1.text = [NSString stringWithFormat:@"%ld",(long)showTextViewNavViewNumberTo1];
    [showTextViewNavViewLabelTo1 addSubview:showTextViewNavViewLabelTo1];
    
    UIImageView * showTextViewNavViewLabelTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [showTextViewNavViewViewTo1 addSubview:showTextViewNavViewLabelTo2];
    
}
- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"功能设置";
    self.listArr = [[NSArray alloc]initWithObjects:@"黑名单",@"隐私设置",@"修改手机号",@"注销账号", nil];
    self.acountTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KScreen_W, KScreen_H-KNav_H)];
    self.acountTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.acountTableView.backgroundColor = viewback_black;
    self.acountTableView.delegate = self;
    self.acountTableView.dataSource = self;
    self.acountTableView.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:self.acountTableView];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.listArr.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    My_editTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"my_cell"];
    if (cell == nil) {
        cell = [[My_editTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"my_cell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.cell_editBtn.userInteractionEnabled = YES;

    cell.bg.backgroundColor = subviewback_black;
    cell.cell_exitBtn.hidden = YES;
    cell.cell_title.hidden = NO;
    cell.cell_editBtn.hidden = NO;
    cell.cell_editBtn_image.hidden = NO;
    cell.cell_title.text = self.listArr[indexPath.row];
//    cell.cell_editBtn.tag = indexPath.row;
//    [cell.cell_editBtn addTarget:self action:@selector(my_settingTap:) forControlEvents:UIControlEventTouchUpInside];
//    [cell.cell_editBtn setTitle:NSLocalizedString(@"", nil) forState:UIControlStateNormal];

    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0){
        QZBackListVC * view = [[QZBackListVC alloc] init];
        [self.navigationController pushViewController:view animated:YES];
    }else if (indexPath.row == 1){
        MyPrivacySettingVC * privacy = [MyPrivacySettingVC new];
        [self.navigationController pushViewController:privacy animated:YES];
    }else if (indexPath.row == 2) {
        MyChangePassVC * change = [MyChangePassVC new];
        [self.navigationController pushViewController:change animated:YES];
    }else if (indexPath.row == 3) {
        KWeakSelf
        [[BSystemAlert shared] showAlertWithTitle:NSLocalizedString(@"是否注销账号？", nil) message:NSLocalizedString(@"账号注销后，账号数据将被清空，并且数据将无法找回。", nil) userData:nil cancelTitle:NSLocalizedString(@"取消", nil) actions:@[NSLocalizedString(@"注销", nil)] actionBlock:^(id  _Nonnull userData, NSString * _Nonnull actionTitle) {
            if ([actionTitle isEqualToString:NSLocalizedString(@"注销", nil)]) {
                KMutableDic(sendDic)
                [YBNetBase userLogoutRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
                    if(code == 200){
                        [QZUserInfoModel cleanUserData];
                        [CSJADLoading dj_SignOutWithPaySecretKey];
                        [YBMsgPop showPop:@"账号注销成功"];
                        [weakSelf saveToken];
                    }else{
                        [YBMsgPop showPop:msg];
                    }
                }];
            }
        }];
        
    }
//        else if (indexPath.row == 2) {
//        KWeakSelf
//        [[BSystemAlert shared] showAlertWithTitle:NSLocalizedString(@"温馨提示", nil) message:NSLocalizedString(@"是否确定要退出登录吗？", nil) userData:nil cancelTitle:NSLocalizedString(@"取消", nil) actions:@[NSLocalizedString(@"退出", nil)] actionBlock:^(id  _Nonnull userData, NSString * _Nonnull actionTitle) {
//            if ([actionTitle isEqualToString:NSLocalizedString(@"退出", nil)]) {
//                KMutableDic(sendDic)
//                [YBNetBase userLogoffRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
//                    if(code == 200){
//                        [QZUserInfoModel cleanUserData];
//                        [YBMsgPop showPop:@"账号已退出"];
//                        [weakSelf saveToken];
//                    }else{
//                        [YBMsgPop showPop:msg];
//                    }
//                }];
//            }
//        }];
//
//    }
}
- (void)saveToken{
    KMutableDic(sendDic)
    sendDic[@"device_token"] = [QZUserInfoModel share].pushToken;
    sendDic[@"is_open"] = @([QZUserInfoModel share].lastPushStatus);
    [YBNetBase saveDeviceTokenRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        
    }];
}
- (void)my_settingTap{
    
}
@end
